package com.qingcloud.adminbackend.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qingcloud.adminbackend.base.AjaxResult;
import com.qingcloud.adminbackend.entity.equipment.EquipmentDTO;
import com.qingcloud.adminbackend.entity.equipment.OrderEquipmentDTO;
import com.qingcloud.adminbackend.entity.sysorder.*;
import com.qingcloud.adminbackend.entity.sysorg.SysUserModuleDTO;
import com.qingcloud.adminbackend.entity.sysorder.*;
import com.qingcloud.base.remote.pojo.BusinessApp;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 订单表 服务类
 * </p>
 *
 * @author liyuhong
 * @since 2018-12-20
 */
public interface ISysOrderService extends IService<SysOrder> {

    /**
     * 查询订单列表
     *
     * @param userId
     * @param sysOrder
     * @return
     */
    IPage<SysOrder> findSysOrderList(String userId, SysOrderPageDTO sysOrder);

    /**
     * 添加修改订单
     *
     * @param sysOrder
     * @return
     */
    AjaxResult setSysOrder(SysOrder sysOrder);

    /**
     * 订单关联客户
     *
     * @param orderId
     * @param orgId
     * @return
     */
    AjaxResult toOrderOrg(String orderId, String orgId);

    /**
     * 删除订单
     *
     * @param orderIds
     * @return
     */
    AjaxResult deleteOrder(List<String> orderIds);

    /**
     * 订单内设备列表
     *
     * @param equipmentDTO
     * @return
     */
    IPage<OrderEquipmentDTO> findOrderEquipmentList(EquipmentDTO equipmentDTO);

    /**
     * 订单详情查看
     *
     * @param orderId
     * @return
     */
    SysOrder findOrderById(String orderId);

    SysOrder findOrderDetail(String id);

    /**
     * 没有关联客户的订单
     *
     * @param businessTypeSet
     * @return
     */
    List<Map> findOrderByBusinessType(Collection<Integer> businessTypeSet);

    /**
     * 已关联客户的订单
     *
     * @param orgId
     * @return
     */
    List<Map> findOrderByOrgId(String orgId);

    /**
     * 客户批量关联订单
     *
     * @param sysOrderBO
     */
    AjaxResult orgToOrders(SysOrderBO sysOrderBO);

    /**
     * 用户授权【售前】写权限的订单
     *
     * @param sysUserOrderMgrDTO
     * @return
     */
    Set<SysUserOrderMgrDTO> getOrders(SysUserOrderMgrDTO sysUserOrderMgrDTO, boolean isAdmin);

    /**
     * 用户授权【运维】读写权限的订单
     *
     * @param sysUserOrderMgrDTO
     * @return
     */
    Set<SysUserOrderMgrDTO> findOrders(SysUserOrderMgrDTO sysUserOrderMgrDTO, boolean isAdmin);

//    /**
//     * 用户所属【销售】的订单
//     *
//     * @param sysUserOrderMgrDTO
//     * @return
//     */
//    List<SysUserOrderMgrDTO> subordinateOrders(SysUserOrderMgrDTO sysUserOrderMgrDTO);

    /**
     * 用户已授权【运维】的订单
     *
     * @param sysUserOrderMgrDTO
     * @return
     */
    List<SysUserOrderMgrDTO> grantedOrders(SysUserOrderMgrDTO sysUserOrderMgrDTO);

//    /**
//     * 用户已选【数据质控】的订单
//     *
//     * @param sysUserOrderMgrDTO
//     * @return
//     */
//    List<SysUserOrderMgrDTO> dataQuality(SysUserOrderMgrDTO sysUserOrderMgrDTO);

    /**
     * 客户及分支机构对应的订单
     *
     * @param orgId
     * @return
     */
    List<Map> findOrderListByOrgId(String orgId);

    /**
     * 所有订单
     *
     * @return
     */
    List<SysUserModuleDTO> findOrderList();

    /**
     * 可管理的订单
     *
     * @param businessType
     * @param userId
     * @param isAdmin
     * @return
     */
    List<SysUserModuleDTO> findOrders(String businessType, String userId, boolean isAdmin);

    /**
     * 用户业务种类下有权限的订单
     *
     * @param orderRequest
     * @return
     */
    Set<SysUserOrderMgrDTO> getOrdersByBusinessType(SysUserOrderRequest orderRequest, boolean isAdmin);

    /**
     * 云平台注册默认订单
     */
    String registerOrder(String company, String orgId);

    /**
     * 根据业务应用编号，来源获取业务应用记录
     * @param orign
     * @param bizCode
     * @return
     */
    SysBusinessApp getSysBusinessAppByCode(Integer orign, String bizCode);

    /**
     * 新增或修改应用
     * @param businessApp
     */
    void registerApp(BusinessApp businessApp);

    /**
     * 删除应用
     * @param id
     */
    void deleteBusinessApp(Integer id,String bizCode);
}
